#ifndef _LOG_H
#define _LOG_H

#include <lib/vsprintf.h>

#define PASS "\033[10m"
#define INFO "\033[15m"
#define WARN "\033[14m"
#define ERRO "\033[12m"

void printk(const char* fmt, ...);

#define panic(fmt, ...) \
    { printk("\033[15;12m[PANIC] " fmt "\033[0m", ##__VA_ARGS__); while (1); }

#ifdef __DEBUG__
#define assert_msg(x, str) \
do { \
    if (!(x)) { \
    panic("Assert! %s:%d: %s", __FILE__, __LINE__, str); \
    } \
} while (0)
#define assert(x) \
do { \
    if (!(x)) { \
    panic("Assert! %s:%d", __FILE__, __LINE__); \
    } \
} while (0)
#else
#define assert_msg(x, str)
#define assert(x)
#endif

#ifdef LOG_TAG
#define LOG(level, fmt, ...) \
    printk("\033[0m"level"["#level"]("LOG_TAG") " fmt "\033[0m", ##__VA_ARGS__)
#else
#define LOG(level, fmt, ...) \
    printk("\033[0m"level"["#level"] " fmt "\033[0m", ##__VA_ARGS__)
#endif

#define LOGI(fmt, ...) LOG(INFO, fmt, ##__VA_ARGS__)
#define LOGW(fmt, ...) LOG(WARN, fmt, ##__VA_ARGS__)
#define LOGE(fmt, ...) LOG(ERRO, fmt, ##__VA_ARGS__)
#define LOGP(fmt, ...) LOG(PASS, fmt, ##__VA_ARGS__)

#endif /* _LOG_H */